//
// Created by haoy on 2017/6/15.
//
#include <ostream>
#include "rtp.h"

std::ostream& operator<< (std::ostream& os, const RTPPacket* p) {
    int csrc_offset = 0;
    char csrc_buf[256];
    for (auto csrc : p->GetRTPHeader().csrcs) {
        csrc_offset = sprintf(csrc_buf + csrc_offset, "%lu,", csrc);
    }
    os << "{"
       << "v:" << (int)p->GetRTPHeader().version << ","
       << "p:" << (int)p->GetRTPHeader().padding << ","
       << "x:" << (int)p->GetRTPHeader().extension << ","
    //    << "cc:[" << std::string(csrc_buf) << "]" << ", "
       << "m:" << (int)p->GetRTPHeader().mark << ","
       << "pt:" << p->GetPayloadType() << ","
       << "seq:" << p->GetSeqNum() << ","
       << "eseq:" << p->GetExtSeqNum() << ","
       << "ts:" << p->GetTimestamp() << ","
       << "ssrc:" << p->GetSSRC() << ","
       << "hl:" << p->GetRTPHeader().GetSize() << ","
       << "pl:" << p->GetMediaLength()
       << "}";
    return os;
}

std::ostream& operator<< (std::ostream& os, const RTPHeader& h) {
    int csrc_offset = 0;
    char csrc_buf[256];
    for (auto csrc : h.csrcs) {
        csrc_offset = sprintf(csrc_buf + csrc_offset, "%lu,", csrc);
    }
    os << "{"
       << "v:" << h.version << ","
       << "p:" << h.padding << ","
       << "x:" << h.extension << ","
       << "cc:[" << std::string(csrc_buf) << "],"
       << "m:" << h.mark << ","
       << "pt:" << h.payloadType << ","
       << "seq:" << h.sequenceNumber << ","
       << "ssrc:" << h.ssrc << ","
       << "hl:" << h.GetSize() << ","
       << "}";
    return os;
}